package com.ks.template.controller;

import com.ks.core.base._ControllerBase;
import com.ks.core.core.Result;
import com.ks.core.dto.SearchCriteriaBase;
import com.ks.template.controller.dto.TemplateFrameRequest;
import com.ks.template.entity.TemplateFrame;
import com.ks.template.service.ITemplateFrameService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


/**
 * <p>
 * 模板模块-小程序模板信息表 前端控制器
 * </p>
 *
 * @author kingdee123
 * @since 2020-12-09
 */
@RestController
@RequestMapping("/adminTemplateFrame")
@Api(value = "管理模块", description = "管理模块")
public class TemplateFrameAdminController extends _ControllerBase {

    @Autowired
    private ITemplateFrameService templateFrameService;

    @PostMapping("/mould")
    @ApiOperation(value = "租户小程序模板清单接口", notes = "租户小程序模板清单接口")
    public Object MouldIndex(@RequestBody SearchCriteriaBase searchCriteriaBase) {
        Map<String, Object> resultMap = templateFrameService.getMouldIndex(getContext(), searchCriteriaBase);
        return Result.success(resultMap);
    }

    @PostMapping("/info")
    @ApiOperation(value = "获取模板详情", notes = "获取模板详情")
    public Object getTemplateFrameInfo(@RequestBody TemplateFrameRequest request) {
        TemplateFrame templateFrameInfo = templateFrameService.getTemplateFrameInfo(request.getId());
        return Result.success(templateFrameInfo);
    }

    @PostMapping("/sysMould")
    @ApiOperation(value = "系统模板清单接口", notes = "系统模板清单接口")
    public Object sysMouldIndex(@RequestBody SearchCriteriaBase searchCriteriaBase) {
        Map<String, Object> resultMap = templateFrameService.getSysMouldIndex(getContext(), searchCriteriaBase);
        return Result.success(resultMap);
    }

    @PostMapping("/sysMouldList")
    @ApiOperation(value = "小程序系统模板清单接口", notes = "小程序系统模板清单接口")
    public Object sysMould(@RequestBody SearchCriteriaBase searchCriteriaBase) {
        Map<String, Object> resultMap = templateFrameService.getSysMouldIndexList(getContext(), searchCriteriaBase);
        return Result.success(resultMap);
    }

    @PostMapping("/isActive")
    @ApiOperation(value = "模板启用停用状态设置接口", notes = "模板启用停用状态设置接口")
    public Object isActive(@RequestBody TemplateFrameRequest request) {
        int resultMap = templateFrameService.isActive(getContext(), request.getId(), request.getState());
        return Result.success(resultMap);
    }

    @PostMapping("/delete")
    @ApiOperation(value = "模板删除接口", notes = "模板删除接口")
    public Object delete(@RequestBody TemplateFrameRequest  request) {
        int resultMap = templateFrameService.delete(getContext(), request.getId());
        return Result.success(resultMap);
    }

    @PostMapping("/add")
    @ApiOperation(value = "模板添加接口", notes = "模板添加接口")
    public Object add(@RequestBody TemplateFrame templateFrame) {
        int resultMap = templateFrameService.add(getContext(), templateFrame);
        return Result.success(resultMap);
    }

    @PostMapping("/update")
    @ApiOperation(value = "模板修改接口", notes = "模板修改接口")
    public Object update(@RequestBody TemplateFrame templateFrame) {
        int resultMap = templateFrameService.update(getContext(), templateFrame);
        return Result.success(resultMap);
    }

}

